fix: restore onChange type inference for single date picker#6205
Merged
martijnrusschen merged 1 commit intomainfrom Jan 5, 2026
Merged
fix: restore onChange type inference for single date picker#6205martijnrusschen merged 1 commit intomainfrom
martijnrusschen merged 1 commit intomainfrom
Conversation
Reverts the discriminated union changes from commit 3a82fd1 that made `selectsRange` and `selectsMultiple` optional in their respective union branches. This broke TypeScript's ability to infer the onChange parameter type when neither prop is specified. The fix restores required `selectsRange: true` and `selectsMultiple: true` in their respective union branches, allowing TypeScript to properly narrow the type and infer `Date | null` for the default single-date case. Users of range/multiple selection already pass these props explicitly (required for runtime behavior), so this change aligns types with actual usage patterns. Wrapper components that need to spread props can use type assertions as a workaround (see issue #6131 for details). Also adds explicit type inference tests to prevent regression. Fixes #6202 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This was referenced Jan 5, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6205 +/- ##
==========================================
- Coverage 99.31% 99.29% -0.03%
==========================================
Files 30 30
Lines 3810 3810
Branches 1639 1659 +20
==========================================
- Hits 3784 3783 -1
- Misses 25 26 +1
Partials 1 1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
onChangecallback parameterProblem
After upgrading to 9.1.0, TypeScript could not infer the type of the
onChangeparameter:This caused the error: "Parameter 'x' implicitly has an 'any' type. (7006)"
Root Cause
Commit 3a82fd1 changed
selectsRange: trueandselectsMultiple: trueto optional (selectsRange?: trueandselectsMultiple?: true) in the discriminated union type. This prevented TypeScript from narrowing the union when neither prop is specified, causing all threeonChangesignatures to be valid simultaneously.Solution
Restore the required discriminators:
selectsRange: true(not optional)selectsMultiple: true(not optional)This allows TypeScript to properly narrow the type when neither prop is passed.
Impact on #6131
The original fix (#6131) was for wrapper components spreading props. Those users can work around this with a type assertion:
This is acceptable because:
selectsRangeandselectsMultiplealready pass these props explicitly (required for runtime behavior)Test plan
type_inference_test.test.tsxto verify TypeScript can infer types without explicit annotationsFixes #6202
🤖 Generated with Claude Code